package cn.edu.jxust.controller.api.air;

import cn.edu.jxust.common.domain.web.api.air.IAqiController;
import cn.edu.jxust.common.response.Result;
import cn.edu.jxust.common.response.ResultUtils;
import cn.edu.jxust.common.response.enums.ResultStatus;
import cn.edu.jxust.core.domain.repository.AqiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * @author QiuKangming
 * @since 2020-06-29
 */
@Slf4j
@RestController
public class AqiController implements IAqiController {

    @Resource
    private AqiService aqiService;

    @Override
    public Result getAqiList(Integer deviceId, String beginTime, String endTime, String aqiType){

        try{
            if (deviceId == null
                    || StringUtils.isEmpty(beginTime)
                    || StringUtils.isEmpty(endTime)
                    || StringUtils.isEmpty(aqiType)) {
                return ResultUtils.resultWithoutData(ResultStatus.PARAM_ERROR, "请选择完整参数信息");
            }
            return aqiService.getAqiList(deviceId, beginTime, endTime, aqiType);

        }catch (Exception e){
            log.error("AqiController --> getAqiList异常: {}", e.getMessage());
            return ResultUtils.resultWithoutData(ResultStatus.FAILED);
        }

    }

    @Override
    public Result getOneAirListPage(Integer deviceId, Integer airType, String beginDate, String endDate){

        try{
            if (deviceId == null
                    || StringUtils.isEmpty(beginDate)
                    || StringUtils.isEmpty(endDate)
                    || airType == null) {
                return ResultUtils.resultWithoutData(ResultStatus.PARAM_ERROR, "请选择完整参数信息");
            }
            return aqiService.getOneAirList(deviceId, airType, beginDate, endDate);

        }catch (Exception e){
            log.error("AqiController --> getOneAirListPage 异常: {}", e.getMessage());
            return ResultUtils.resultWithoutData(ResultStatus.FAILED);
        }

    }

}

